export default {
	formatDate2: ( date, format ) => {
		let oldDate = new Date( date )
		let newDate = null
		let year = oldDate.getFullYear()
		let month = oldDate.getMonth() + 1
		let day = oldDate.getDate()

		switch ( format ) {
			case 'yyyy-MM-dd':
				newDate = year + '-' + month + '-' + day
				break
			case 'yyyy/MM/dd':
				newDate = year + '/' + month + '/' + day
				break
			default:
				newDate = year + '-' + month + '-' + day
		}
		return newDate
	},

	getCookie: ( name ) => {
		let arr,
			reg = new RegExp( "(^| )" + name + "=([^;]*)(;|$)" );
		if ( arr = document.cookie.match( reg ) )
			return unescape( arr[ 2 ] );
		else {
			return null;
		}
	},

	//写cookies
	setCookie: ( name, value ) => {
		let exp = new Date();
		exp.setTime( exp.getTime() + 24 * 60 * 60 * 1000 );
		document.cookie = name + "=" + escape( value ) + ";expires=" + exp.toGMTString();
	},

	formatDate: ( format ) => {
		let oldDate = new Date( format );
		let date = {
			"M+": oldDate.getMonth() + 1,
			"d+": oldDate.getDate(),
			"h+": oldDate.getHours(),
			"m+": oldDate.getMinutes(),
			"s+": oldDate.getSeconds(),
			"q+": Math.floor( ( oldDate.getMonth() + 3 ) / 3 ),
			"S+": oldDate.getMilliseconds()
		};

		var month = oldDate.getMonth() + 1;
		if ( month < 10 ) {
			month = "0" + month;
		}

		var day = oldDate.getDate();
		if ( day < 10 ) {
			day = "0" + day;
		}

		var hour = oldDate.getHours();
		if ( hour < 10 ) {
			hour = "0" + hour;
		}

		var min = oldDate.getMinutes();
		if ( min < 10 ) {
			min = "0" + min;
		}

		var res = oldDate.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + min;
		return res;
	},

	formatDate0: ( format ) => {
		let oldDate = new Date( format );
		let date = {
			"M+": oldDate.getMonth() + 1,
			"d+": oldDate.getDate(),
			"h+": oldDate.getHours(),
			"m+": oldDate.getMinutes(),
			"s+": oldDate.getSeconds(),
			"q+": Math.floor( ( oldDate.getMonth() + 3 ) / 3 ),
			"S+": oldDate.getMilliseconds()
		};

		var month = oldDate.getMonth() + 1;
		if ( month < 10 ) {
			month = "0" + month;
		}

		var day = oldDate.getDate();
		if ( day < 10 ) {
			day = "0" + day;
		}

		var hour = oldDate.getHours();
		if ( hour < 10 ) {
			hour = "0" + hour;
		}

		var min = oldDate.getMinutes();
		if ( min < 10 ) {
			min = "0" + min;
		}

		var res = month + '-' + day + ' ' + hour + ':' + min;
		return res;
	},

	formatDate1: ( format ) => {
		let oldDate = new Date( format );
		let date = {
			"M+": oldDate.getMonth() + 1,
			"d+": oldDate.getDate(),
			"h+": oldDate.getHours(),
			"m+": oldDate.getMinutes(),
			"s+": oldDate.getSeconds(),
			"q+": Math.floor( ( oldDate.getMonth() + 3 ) / 3 ),
			"S+": oldDate.getMilliseconds()
		};

		var month = oldDate.getMonth() + 1;
		if ( month < 10 ) {
			month = "0" + month;
		}

		var day = oldDate.getDate();
		if ( day < 10 ) {
			day = "0" + day;
		}

		var hour = oldDate.getHours();
		if ( hour < 10 ) {
			hour = "0" + hour;
		}

		var min = oldDate.getMinutes();
		if ( min < 10 ) {
			min = "0" + min;
		}

		var res = oldDate.getFullYear() + '/' + month + '/' + day + ' ' + hour + ':' + min;
		return res;
	}

}